package fr.umlv.m2.jee.pmlv.service.cursus.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import fr.umlv.m2.jee.pmlv.persistence.cursus.Specialty;
import fr.umlv.m2.jee.pmlv.persistence.cursus.dao.ISpecialtyDAO;
import fr.umlv.m2.jee.pmlv.service.cursus.DisplaySpecialty;
import fr.umlv.m2.jee.pmlv.service.cursus.IDisplaySpecialtyService;
import org.springframework.transaction.annotation.Transactional;

@Service("defautDisplaySpecialtyService")
public class DefautDisplaySpecialtyService implements IDisplaySpecialtyService {

    @Autowired
    @Qualifier("hibernateSpecialtyDAO")
    private ISpecialtyDAO dao;
	  	  
    @Override
    @Transactional(readOnly=true)
    public List<DisplaySpecialty> getAllDisplaySpecialty() {
        ArrayList< DisplaySpecialty > result = new ArrayList< DisplaySpecialty >(16);
        for(Specialty specialty : dao.findAll() ) {
            result.add(new DisplaySpecialty(specialty));
        }

        return result;
    }

    @Override
    @Transactional(readOnly=true)
    public DisplaySpecialty getDisplaySpecialtyById(String id) {
        return new DisplaySpecialty(dao.findById(Long.parseLong(id)));
    }
}
